<?php

namespace app\operation\command;

use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\facade\Log;

class sendMessage extends Command
{
    protected function configure()
    {
        // 指令配置
       $this->setName('sendMessage')->setDescription("发送消息");
       $this->addArgument('id',  \think\console\input\Argument::OPTIONAL, "The name of the id","");
    }

    protected function execute(Input $input, Output $output)
    {
      
        Log::info('------推送CMD执行------');
        set_time_limit(0);
        
        $config = new \app\admin\model\Config();
        config($config->getConfig(),'app');

        $data = $input->getArguments();	
        $id = $data['id'] ?? 0;	
        if(!$id){        
            Log::error("id not found");   
            exit();
        }           
        try {
            $msg = new \app\operation\model\SystemMessage();
            $message = $msg->get($id);
            if($message){
                $msg->sendMsg($message); 
            }           
        } catch (\Exception $e) {             
            Log::error($e->getMessage());
        } catch(\Error $e){
            Log::error($e->getMessage());    
        }
        Log::info('------推送CMD执行结束------');
    }
    
    
   
}
